home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LT_FindMenuCommand.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  2KB  |  90 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. **
  6. **  :ts=4
  7. */
  8.  
  9. #include "gtlayout_global.h"
  10.  
  11. #ifdef DO_MENUS
  12.  
  13.     /* LT_FindMenuCommand(struct Menu *Menu,UWORD MsgCode,UWORD MsgQualifier,struct Gadget *MsgGadget):
  14.      *
  15.      *    Find the menu a key command is associated with; this includes only commands
  16.      *    Intuition does not process by itself.
  17.      */
  18.  
  19. struct MenuItem * LIBENT
  20. LT_FindMenuCommand(REG(a0) struct Menu *Menu,REG(d0) UWORD MsgCode,REG(d1) UWORD MsgQualifier,REG(a1) struct Gadget *MsgGadget)
  21. {
  22.     if(!Menu)
  23.         return(NULL);
  24.  
  25.         // Only take care of downstrokes
  26.  
  27.     if(!(MsgCode & IECODE_UP_PREFIX))
  28.     {
  29.         RootMenu            *Root = (RootMenu *)((ULONG)Menu - offsetof(RootMenu,Menu));
  30.         ItemNode            *Item;
  31.         struct InputEvent     Event;
  32.         UBYTE                 ANSIKey[10];
  33.         ULONG                 Qualifier;
  34.  
  35.             // Fix up the MsgQualifier
  36.  
  37.         if(MsgQualifier & QUALIFIER_SHIFT)
  38.             MsgQualifier = (MsgQualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
  39.  
  40.         if(MsgQualifier & QUALIFIER_ALT)
  41.             MsgQualifier = (MsgQualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
  42.  
  43.             // Convert the key
  44.  
  45.         ANSIKey[0] = 0;
  46.  
  47.         Event . ie_NextEvent    = NULL;
  48.         Event . ie_Class        = IECLASS_RAWKEY;
  49.         Event . ie_SubClass        = 0;
  50.         Event . ie_Code            = MsgCode;
  51.         Event . ie_Qualifier    = MsgQualifier;
  52.         Event . ie_EventAddress    = (APTR)MsgGadget;
  53.  
  54.         if(!MapRawKey(&Event,ANSIKey,9,NULL))
  55.             ANSIKey[0] = 0;
  56.  
  57.             // Run down the list...
  58.  
  59.         for(Item = (ItemNode *)Root -> ItemList . mlh_Head ; Item -> Node . mln_Succ ; Item = (ItemNode *)Item -> Node . mln_Succ)
  60.         {
  61.                 // See if we can do with the char
  62.  
  63.             if(Item -> Char)
  64.             {
  65.                 if(Item -> Char == ANSIKey[0])
  66.                     return(&Item -> Item);
  67.             }
  68.             else
  69.             {
  70.                     // So that didn't work, what about the raw data?
  71.  
  72.                 Qualifier = Item -> Qualifier;
  73.  
  74.                 if(Qualifier & QUALIFIER_SHIFT)
  75.                     Qualifier = (Qualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
  76.  
  77.                 if(Qualifier & QUALIFIER_ALT)
  78.                     Qualifier = (Qualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
  79.  
  80.                 if(Item -> Code == MsgCode && (MsgQualifier & Qualifier) == Qualifier)
  81.                     return(&Item -> Item);
  82.             }
  83.         }
  84.     }
  85.  
  86.     return(NULL);
  87. }
  88.  
  89. #endif    /* DO_MENUS */
  90.